package com.syaccp.config.security.handler;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import com.syaccp.utils.Result;

import cn.hutool.json.JSONUtil;


@Component

public class AccessDeniedHandlerImpl implements AccessDeniedHandler {

	@Override
	public void handle(HttpServletRequest request, HttpServletResponse response,
			AccessDeniedException accessDeniedException) throws IOException, ServletException {
		//设置客户端响应编码格式
        response.setContentType("application/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String result = JSONUtil.toJsonStr(Result.NO_AUTH("无权限访问,请联系管理员！"));
        out.println(result);
        out.flush();
        out.close();

	}

}
